#pragma once 

class Shader;
class RunningManager;
class texture;

class Terrain
{
public:
    static Terrain* getInstance();

	void initGeometry();
	void initShader();
	void initPickingFBO();

	void render(const glm::mat4& viewMatrix, bool picking=false);
    
    glm::vec2 pick(const glm::vec4& pixel);

    float sample(const glm::vec2 & pos);
	glm::vec3 gradient(const glm::vec2 & pos);
	bool walkable(const glm::vec2 & pos, float radius);

	glm::vec4 getExtent() { return glm::vec4(0.0f, 0.0f, width, height); }

private:
    Terrain();
    static Terrain* instance;
    void renderTerrain(Shader* renderShader, const glm::mat4& viewMatrix);
	float width;
	float height;
	size_t nVertsWidth;
	size_t nVertsHeight;
	GLuint vbo;
	GLuint ibo;
	GLuint vao;
	 
    Texture normalTex;
    Texture heightTex;

    std::vector<float> heights;
	std::vector<PTVertex> vertices;
	std::vector<unsigned int> indices;
	GLuint quadBuffer;
	GLuint quadVAO;
	std::vector<glm::vec2> quadVertices;

	Shader* defaultShader;
	Shader* pickingShader;

    /*GLuint heightFBO;*/
    FBO_Tex heightFBO;
};